package com.example.zwgt.yrfk.ui.mine.activity;

import android.util.Log;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.zwgt.yrfk.R;
import com.example.zwgt.yrfk.base.mvpbase.BasePresenter;
import com.example.zwgt.yrfk.base.mvpbase.baseImpl.BaseActivity;

import butterknife.BindView;


/**
 * 跳转到这个页面需要携带地址信息
 */
public class WebViewActivity extends BaseActivity implements View.OnClickListener {


    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.webview)
    WebView webview;


    @Override
    public int getLayoutId() {
        return R.layout.activity_web_view;
    }

    @Override
    public BasePresenter initPresenter() {
        return null;
    }

    @Override
    protected void initViews() {
        initview();
    }

    private void initview() {
        String url = getIntent().getStringExtra("url");
        Log.e("url", url);
        //启用支持javascript
        WebSettings settings = webview.getSettings();
        settings.setJavaScriptEnabled(true);  //支持js
        settings.setUseWideViewPort(true);  //将图片调整到适合webview的大小
        settings.setSupportZoom(true);  //支持缩放
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); //支持内容重新布局
        settings.supportMultipleWindows();  //多窗口
        settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);  //关闭webview中缓存
        settings.setAllowFileAccess(true);  //设置可以访问文件
        settings.setNeedInitialFocus(true); //当webview调用requestFocus时为webview设置节点
        settings.setBuiltInZoomControls(true); //设置支持缩放
        settings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口
        settings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小
        settings.setLoadsImagesAutomatically(true);  //支持自动加载图片
        webview.loadUrl(url);
        ivBack.setOnClickListener(this);
        if (url.equals("http://api.zwgt.com/index-app_zwgt.html")) {
            tvTitle.setText("公司介绍");
        } else if (url.equals("http://api.zwgt.com/index-app_product.html")) {
            tvTitle.setText("关于产品");
        } else if (url.equals("http://api.zwgt.com/index-app_partner.html")) {
            tvTitle.setText("合作伙伴");
        } else if (url.equals("http://api.zwgt.com/index-app_contact.html")) {
            tvTitle.setText("联系我们");
        } else {
            tvTitle.setText("关于我们");
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }
}
